class ParseError(Exception):
    pass


class JsonParser:
    def find_json_matches(self, finder, json_node):
        return finder.find(json_node)

    def find_match_values(self, finder, json_node):
        return [match.value for match in finder.find(json_node)]

    def only_match_value(self, finder, json_node):
        vals = self.find_match_values(finder, json_node)
        if len(vals) != 1:
            raise ParseError(
                "finder:%s find NOT one value in json node:%s" % (finder, json_node)
            )

        return vals[0]

    def at_most_one_match_value(self, finder, json_node):
        vals = self.find_match_values(finder, json_node)
        if len(vals) > 1:
            raise ParseError(
                "finder:%s find MORE THAN one value in json node:%s"
                % (finder, json_node)
            )

        return vals[0] if vals else None
